require("../css/home.less");

const axios = require("../utils/axiosUtil.js");

const utils = require('../utils/utils.js');


window.onload = function () {
    var mySwiper = new Swiper('.swiper', {
        loop: true, // 循环模式选项
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },
        autoplay: {
            delay: 1000,
            stopOnLastSlide: false,
            disableOnInteraction: false,
            pauseOnMouseEnter: true   //鼠标移入移出  
        },
    })

    let ranking = document.querySelector('.ranking span');
    let clockCount = document.querySelector('.clock-count span');
    let badges = document.querySelector('.badges span');
    let clockBtn = document.querySelector(".clock-btn");

    //   进入页面请求 用户的打卡数据（天数 排名 徽章）
    function con() {
        axios.get('/api/user/info').then(function (res) {
            console.log(res);

            ranking.innerText = res.data.data.ranking
            clockCount.innerText = res.data.data['member.clockCount'];
            badges.innerText = res.data.data.badges;
        })

        //是否打卡
        axios.get('/api/user/clockInInfo').then(function (res) {
            if (res.data.data.isClockIn) {
                clockBtn.classList.add("active");
            }
        })
    }

    con();
    //打卡
    clockBtn.addEventListener("click", function () {
        // clockBtn.classList.add("active");
        axios.post('/api/user/clockIn').then(function (res) {
            if (res.data.errno == 0) {
                utils.toast(0, "打卡成功")
                getUserInfo()
            } else {
                utils.toast(1, res.data.message);
            }
        })
    })

    //运动数据
    document.querySelector(".data").addEventListener("click", function () {
        location.href = "../yundong.html"
    })

    utils.footer("home");
}

